<?php


namespace app\api\controller;


use app\api\BaseApi;
use app\service\NewsService;
use app\service\UserService;
use think\response\Json;

class News extends BaseApi
{

    /**
     * 分页获取系统公告列表
     * @return Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getNoticeListForPage(): Json{
        $user_token = trim(input('user_token'));
        if (empty($user_token)) {
            return $this->error('非法访问', '', $this::ERROR_CODE);
        }
        $page = trim(input('page'));
        $size = trim(input('size'));
        //检查用户是否在线
        $userService = new UserService();
        $userInfo = $userService->checkUerIsOnlineByToken($user_token);
        if ($userInfo['status'] == 0) {
            return $this->error($userInfo['msg'], '', $userInfo['data']);
        }
        $newsService = new NewsService();
        $result = $newsService -> getNoticeListForPage($page,$size);
        return $this->success($result['msg'], $result['data']);
    }

}